

def __calc_count__(ele):
    return ele[1]


def __data_map__(instances, attr_name, value_converter):
    dict_map = {}
    for item in instances:
        attr_value = item[attr_name]
        if value_converter:
            attr_value = value_converter(attr_value)
        if attr_value in dict_map:
            dict_map[attr_value] += 1
        else:
            dict_map.setdefault(attr_value, 1)
    return dict_map


def __sort_col__(data_dict):
    items = data_dict.items()
    c = []
    for item in items:
        c.append(item)
    c.sort(key=lambda ele: ele[1], reverse=True)
    return c;


def filter_count(instances, attr_name, value_converter=None):
    return __sort_col__(__data_map__(instances, attr_name, value_converter))